-- Autocmds are automatically loaded on the VeryLazy event
-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
--
-- Add any additional autocmds here
-- with `vim.api.nvim_create_autocmd`
--
-- Or remove existing autocmds by their group name (which is prefixed with `lazyvim_` for the defaults)
-- e.g. vim.api.nvim_del_augroup_by_name("lazyvim_wrap_spell")

local project = require("project_nvim")

-- filetype: python
vim.api.nvim_create_autocmd("BufReadPost", {
  pattern = "*.py",
  callback = function()
    vim.cmd("setlocal ft=python")
  end,
})

-- 设置 python 文件类型
vim.api.nvim_create_autocmd("FileType", {
  pattern = "python",
  callback = function()
    -- 设置缩进为 4 个空格
    vim.bo.tabstop = 4
    vim.bo.shiftwidth = 4
    vim.bo.softtabstop = 4
    vim.bo.expandtab = true
    -- 设置自动缩进
    vim.bo.autoindent = true
    vim.bo.smartindent = true
  end,
})

-- filetype: lua
vim.api.nvim_create_autocmd("BufReadPost", {
  pattern = "*.lua",
  callback = function()
    vim.cmd("setlocal ft=lua")
  end,
})

vim.api.nvim_create_autocmd("FileType", {
  pattern = "lua",
  callback = function()
    -- 设置缩进为 4 个空格
    vim.bo.tabstop = 4
    vim.bo.shiftwidth = 4
    vim.bo.softtabstop = 4
    vim.bo.expandtab = true
    -- 设置自动缩进
    vim.bo.autoindent = true
    vim.bo.smartindent = true
    print("FileType has been set to lua.")
  end,
})

vim.api.nvim_create_autocmd("BufReadPost", {
  pattern = "*.lua",
  callback = function()
    vim.cmd("setlocal ft=lua")
  end,
})

-- 设置 lua 文件类型的缩进
vim.api.nvim_create_autocmd("FileType", {
  pattern = "lua",
  callback = function()
    -- 设置缩进为 2 个空格
    vim.bo.tabstop = 4
    vim.bo.shiftwidth = 4
    vim.bo.softtabstop = 4
    vim.bo.expandtab = true
    -- 设置自动缩进
    vim.bo.autoindent = true
    vim.bo.smartindent = true
  end,
})

-- 设置 MATLAB 文件类型的缩进
vim.api.nvim_create_autocmd("FileType", {
  pattern = "matlab",
  callback = function()
    -- 设置缩进为 2 个空格
    vim.bo.tabstop = 4
    vim.bo.shiftwidth = 4
    vim.bo.softtabstop = 4
    vim.bo.expandtab = true
    -- 设置自动缩进
    vim.bo.autoindent = true
    vim.bo.smartindent = true
  end,
})

-- 项目特定配置自动加载
vim.api.nvim_create_autocmd("VimEnter", {
  callback = function()
    -- 加载项目特定配置
    local project_config = vim.fn.getcwd() .. "/.nvim.lua"
    if vim.fn.filereadable(project_config) == 1 then
      vim.cmd("source " .. project_config)
    end

    -- 原有的项目管理代码
    local custom_projects = {
      "~/AppData/Local/nvim/",
      "~/AppData/Local/nvim-data/lazy/lazy.nvim",
      -- 添加你的项目路径
    }

    for _, project_path in ipairs(custom_projects) do
      local full_path = vim.fn.expand(project_path)
      if vim.fn.isdirectory(full_path) == 1 then
        -- 这里可能需要根据 project.nvim 的 API 来添加项目
        -- 具体方法请参考 project.nvim 的文档
        project.get_recent_projects()
      end
    end
  end,
})
